using UnityEngine;
using UnityEngine.AI;
using System.Collections.Generic;
using Unity.AI.Navigation;

namespace TowerDefence_Zombie
{
    public class RuntimeNavMeshBaker : MonoBehaviour
    {
        private NavMeshSurface navSurface;

        private void Awake()
        {
            navSurface = gameObject.AddComponent<NavMeshSurface>();
            navSurface.agentTypeID = NavMesh.GetSettingsByIndex(0).agentTypeID;
            navSurface.layerMask = LayerMask.GetMask("MapGround");
            navSurface.useGeometry = NavMeshCollectGeometry.PhysicsColliders;
            BakeNavMesh();
            int childCount = transform.childCount;
            for (int i = 0; i < childCount; i++)
            {
                transform.GetChild(i).gameObject.SetActive(false);
            }
        }

        public void BakeNavMesh()
        {
            if (navSurface != null)
            {
                navSurface.BuildNavMesh();
                Debug.Log("NavMesh baked successfully!");
            }
        }
    }
}